package com.rd.student.jike.class1.fangzhou.day0809;

import java.util.Scanner;

public class Test01 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s;
        System.out.print("请输入四位数字：");
        s = sc.next();
        System.out.print("加密后的数字：");
        System.out.println(jiami(s));
        System.out.print("再次解密后的数字：");
        System.out.println(jiemi(jiami(s)));
//        System.out.print("请输入六位数字：");
//        s = sc.next();
//        System.out.print("加密后的数字：");
//        System.out.println(jiami02(s));
//        System.out.print("再次解密后的数字：");
//        System.out.println(jiemi02(jiami02(s)));
    }

    public static  String jiami(String s){
        char[] cArr = s.toCharArray();
        for (int i = 0; i < cArr.length; i++) {
            cArr[i] += 5;
            if(cArr[i]>='0'+10){
                cArr[i] -= 10;
            }
        }

        for(int i = 0;i<2;i++){
            char temp = cArr[i];
            cArr[i] = cArr[cArr.length-1-i];
            cArr[cArr.length-1-i] = temp;
        }
        String ss="";
        for (int i = 0; i < cArr.length; i++) {
            ss+=cArr[i];
        }
        return ss;
    }

    public static  String jiemi(String s){
        String ss = "";
        char[] cArr = s.toCharArray();
        for (int i = 0; i < cArr.length; i++) {
            if(cArr[i]<'0'+ 5){
                cArr[i] += 10;
            }
            cArr[i] -= 5;
        }
        for(int i = 0;i<2;i++){
            char temp = cArr[i];
            cArr[i] = cArr[cArr.length-1-i];
            cArr[cArr.length-1-i] = temp;
        }
        for (int i = 0; i < cArr.length; i++) {
            ss+=cArr[i];
        }
        return ss;
    }
    public static  String jiami02(String s){
        char[] cArr = s.toCharArray();
        int[] arr = new int[6];
        for (int i = 0; i < arr.length; i++) {
            arr[i]=cArr[i]-'0';
        }
        for (int i = 0; i < arr.length; i++) {
            arr[i] += 6;
            if(arr[i]>=12){
                arr[i] -= 12;
            }
        }

        for(int i = 0;i<3;i++){
            int temp = cArr[i];
            arr[i] = arr[arr.length-1-i];
            arr[arr.length-1-i] = temp;
        }
        String ss="";
        for (int i = 0; i < arr.length; i++) {
            ss+=arr[i];
        }
        return ss;
    }
}
